//引入createSlice和 configureStore
import { createSlice, configureStore } from '@reduxjs/toolkit'

// 创建slice对象
const countSlice = createSlice({
  name: 'xxx',
  initialState: { c: 0, msg: '哈哈哈' },
  reducers: {
    add(state, action) {
      state.c = state.c + action.payload
    },
    sub(state, action) {
      state.c = state.c - action.payload
    },
  },
})

// 创建store

export const store = configureStore({
  reducer: {
    count: countSlice.reducer,
  },
})

// 导出action
// add和sub是actionCreator
export const { add, sub } = countSlice.actions
